package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.FacilityService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: FacilityController
 * Package: com.atguigu.lease.web.admin.controller.apartment
 * Description:
 *
 * @Author ygf
 * @Create 2024/9/13 9:36
 * @Version 1.0
 */
@Tag(name = "配套管理接口")
@RestController
@RequestMapping("/admin/facility")
public class FacilityController {

    @Autowired
    private FacilityService facilityService;


    @Operation(summary = "新增或修改配套信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo){
        //调用service层
        facilityService.saveOrUpdate(facilityInfo);
        return Result.ok();
    }

    @Operation(summary = "根据id删除配套信息")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Long id){
        //调用service层
        facilityService.removeById(id);
        return Result.ok();
    }


    //TODO 未测试查出数据 报错类型无法转换  原因是我没配枚举类型转换器工厂
    @Operation(summary = "[根据类型]查询配套信息列表")
    @GetMapping("list")
    public Result<List<FacilityInfo>> listFacility(@RequestParam(required = false) ItemType type) {
        LambdaQueryWrapper<FacilityInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(type != null, FacilityInfo::getType, type);
        List<FacilityInfo> list = facilityService.list(queryWrapper);
        return Result.ok(list);
    }
}
